{include file="common/head"/}
<style>
    .layui-input-2,.layui-input-4{
        float: none;
    }
    .layui-input-4,.layui-input-2{
        margin-right: 0;
    }
</style>
<div class="admin-main layui-anim layui-anim-upbit">
    <fieldset class="layui-elem-field layui-field-title">
        <legend>退款订单列表</legend>
    </fieldset>

    <blockquote class="layui-elem-quote layer-clear">
        <div class="demoTable layui-row layui-input-4">
            <div class="layui-form layui-form-pane" style="float:left;">
                <div class="layui-form-item">
                    <label class="layui-form-label">用户手机号</label>
                    <div class="layui-input-inline layui-form">
                        <input class="layui-input" name="phone" id="key" placeholder="请输入用户手机号">
                    </div>
                </div>
            </div>
        </div>
        <div class="demoTable layui-row layui-input-4">
            <div class="layui-form layui-form-pane" style="float:left;">
                <div class="layui-form-item">
                    <label class="layui-form-label">订单编号</label>
                    <div class="layui-input-inline layui-form">
                        <input class="layui-input" name="order_number" id="order" placeholder="请输入订单编号">
                    </div>
                </div>
            </div>
        </div>
        <div class="demoTable layui-row layui-input-4">
            <div class="layui-form layui-form-pane" style="float:left;">
                <div class="layui-form-item">
                    <label class="layui-form-label">退款状态</label>
                    <div class="layui-input-inline layui-form">
                        <select name="status" lay-filter="interest-search" lay-search placeholder="请选择订单状态"
                            id="status">
                            <option value="-1">请选择订单状态</option>
                            <option value="2">申请退款</option>
                            <option value="3">已退款</option>
                            <option value="4">退款驳回</option>
                        </select>
                    </div>
                </div>
            </div>
        </div>
        <div class="demoTable layui-row layui-input-4">
            <div class="layui-form layui-form-pane" style="float:left;">
                <div class="layui-form-item">
                    <label class="layui-form-label">开始时间</label>
                    <div class="layui-input-4">
                        <input type="text" style="width: 190px;"  name="paytime" value="" lay-verify="paytime"
                        id="paytime"    placeholder="通过时间搜索" class="layui-input" autocomplete="off">
                    </div>
                </div>
            </div>
        </div>
        <div class="demoTable layui-row layui-input-4">
            <div class="layui-form layui-form-pane" style="float:left;">
                <div class="layui-form-item">
                    <label class="layui-form-label">结束时间</label>
                    <div class="layui-input-4">
                        <input type="text" style="width: 190px;"  name="oldtime" value="" lay-verify="oldtime"
                        id="oldtime"    placeholder="通过时间搜索" class="layui-input" autocomplete="off">
                    </div>
                </div>
            </div>
        </div>

        <div class="demoTable layui-row layui-input-4 thio2">
            <button class="layui-btn" style="margin-left:30px;margin-top:7px" id="search"
                data-type="reload">{:lang('search')}</button>
            <a href="{:url('index')}" style="margin-top:7px" class="layui-btn">{:lang('reset')}</a>
        </div>
    </blockquote>
    <fieldset class="layui-elem-field layui-field-title">
        <legend>住房订单列表</legend>
    </fieldset>
    <table class="layui-table" id="list" lay-filter="list"></table>
</div>
{include file="common/foot"/}
<script type="text/html" id="avatarUrl">
	<img src="{{d.avatar}}" style="width:40%;height:100%;"/>
</script>
<script type="text/html" id="eqimgUrl">
	<img src="{{d.eqimg}}" style="width:40%;height:100%;"/>
</script>

<script type="text/html" id="open">
    {{# if(d.status==0){ }}
    待支付
    {{# }else if(d.status==1){ }}
    已支付
    {{# }else if(d.status==2){ }}
    申请退款
    {{# }else if(d.status==3){ }}
    已退款
    {{# }else if(d.status==4){ }}
    退款驳回
    {{# }else if(d.status==5){ }}
    已入住
    {{# }else{ }}
    已完成
    {{# } }}
</script>




<script type="text/html" id="action">
    <a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="edit">{:lang('edit')}</a>
    <!-- <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">{:lang('del')}</a> -->
</script>

<script type="text/html" id="type">
    {{# if(d.type == 0){  }}
    微信支付
    {{# }else if(d.type == 1){   }}
    次卡支付
    {{# }else{ }}
    余额支付
    {{# } }}
</script>
<script type="text/html" id="cate">
    {{# if(d.one_cate==0){}}
        过夜房-{{d.two_cate}}
    {{# }else{}}
        钟点房-{{d.two_cate}}
    {{#}}}
</script>
<script>

    layui.use('laydate', function () {
        var laydate = layui.laydate;
        laydate.render({
            elem:'#paytime'
        })
        laydate.render({
            elem:'#oldtime'
        })
    })
    layui.use(['table', 'form'], function () {
        var table = layui.table, form = layui.form, $ = layui.jquery;
        var tableIn = table.render({
            id: 'ad',
            elem: '#list',
            url: '{:url("index")}',
            method: 'post', 
            page: true,
            cols: [[
                { field: 'id', align: 'center', title: '{:lang("id")}', width: 80,sort: true,hide:true },
                { field: 'order_number', align: 'center', title: '订单编号', width: 150, },
                { field: 'realname', align: 'center', title: '会员名', width: 150 },
                { field: 'phone', align: 'center', title: '会员手机号', width: 150 },
                { field: 'cate', align: 'center', title: '房间分类', width: 150,toolbar:'#cate' },//一级+二级
                { field: 'refund_type', align: 'center', title: '退款类型', width: 150 },
                { field: 'days', align: 'center', title: '天数', width: 80 },
                { field: 'money', align: 'center', title: '下单金额', width: 150 },
                { field: 'addtime', align: 'center', title: '下单时间', width: 120 },
                { field: 'status', align: 'center', title: '订单状态', width: 100, toolbar: '#open' },
                { field: 'type', align: 'center', title: '支付方式', width: 100, toolbar: '#type' },
                { width: 160, align: 'center', title: '{:lang("action")}', toolbar: '#action' ,fixed: 'right', }
            ]],
            limit: ''
        });
        //搜索
        $('#search').on('click', function () {
            var phone = $('#key').val();
            let status = $('#status').val();
            let paytime = $('#paytime').val()
            let oldtime = $('#oldtime').val()
            let order_num = $('#order').val()
            //alert(addtime);
            if ($.trim(phone) === '' && $.trim(status) === -1 && $.trim(paytime)==null && $.trim(oldtime)==null  && $.trim(order_num)==='') {
                layer.msg('{:lang("query_condition")}', { icon: 0 });
                return;
            }
            
            if(paytime){
                paytime = new Date(paytime.replace(/\-/g,','))/1000
            }else{
                paytime = 0
            }
            if(oldtime){
                oldtime = new  Date(oldtime.replace(/\-/g,','))/1000
            }else{
                oldtime = 0
            }
            let where = { phone: phone, status: status == -1 ? '' : status,paytime:paytime,oldtime:oldtime==0?'':oldtime,order_number:order_num }
            if (status == -1) {
                delete where.status
            }
            if (oldtime == 0) {
                delete where.oldtime
            }
            if(paytime ==0){
                delete where.paytime
            }
            if(!phone){
                delete where.phone
            }
            if(!order_num){
                delete where.order_number
            }

            tableIn.reload({
                where: where
            });







        });

        // form.on('switch(open)', function (obj) {
        //     loading = layer.load(1, { shade: [0.1, '#fff'] });
        //     var id = obj.elem.getAttribute('user_id');
        //     var is_open = obj.elem.checked === true ? 0 : 1;
        //     $.post('{:url("adminState")}', { 'user_status': is_open, 'user_id': id }, function (res) {
        //         layer.close(loading);
        //         if (res.errorCode == 0) {
        //             layer.msg(res.msg, { time: 1000, icon: 1 });
        //             tableIn.reload();
        //         } else {
        //             layer.msg(res.msg, { time: 1000, icon: 2 }, function () {
        //                 location.href = res.url;
        //             });
        //             return false;
        //         }

        //     })
        // });
        table.on('tool(list)', function (obj) {
            //获取当前点击行的数据
            var data = obj.data;
            if (obj.event === 'del') {
                layer.confirm('确定要删除该数据吗！', function (index) {
                    var loading = layer.load(1, { shade: [0.1, '#fff'] });
                    $.post("{:url('orderDel')}", { order_id: data.id }, function (res) {
                        layer.close(loading);
                        if (res.errorCode == 8888) {
                            layer.msg(res.msg, { time: 1000, icon: 1 });
                            obj.del();
                        } else {
                            layer.msg(res.msg, { time: 1000, icon: 2 });
                        }
                    });
                    layer.close(index);
                });
            }
            if (obj.event === 'edit') {
                location.href = `/admin/refund/edit.html?id=${data.id}`
            }
        });
    })
</script>